<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function arr(nums, k) {
      const n = nums.length, map = new Map([[0, 1]])
      let sum = 0
      let cnt = 0
      for (let i = 0; i < n; i++) {
        sum = ((nums[i] + sum) % k + k) % k
        if (map.has(sum)) {
          cnt += map.get(sum)
        }
        map.set(sum, (map.get(sum) || 0) + 1)
      }
      return cnt
    };
    console.log(arr([4, 5, 0, -2, -3, 1], 5));
  </script>
</body>

</html>